<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
               label-width="100px">
        <el-form-item label="邀请码" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入邀请码"
            clearable
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item label="用户名" prop="userName">
          <el-input
            v-model="queryParams.userName"
            placeholder="请输入用户名称"
            clearable
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb10">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="flowList" @selection-change="handleSelectionChange" border stripe>
        <el-table-column type="selection" width="50" align="center"/>
        <el-table-column label="邀请码" align="center" prop="code"/>
        <el-table-column label="用户名" align="center" prop="userName"/>
        <el-table-column label="身份证" align="center" prop="agentIdCard" width="300">
          <template slot-scope="scope">
            <div style="display: flex;justify-content: center">
              <div class="mr20">
                <imagePreview :src="scope.row.agentIdCard.split(';')[0]" width="100px" height="60px"/>
              </div>
              <imagePreview :src="scope.row.agentIdCard.split(';')[1]" width="100px" height="60px"/>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="真实姓名" align="center" prop="realName"/>
        <el-table-column label="证书" align="center" prop="certificate" width="120"/>
        <el-table-column label="状态" align="center" prop="status" width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.pay_later_status" :value="scope.row.status"></dict-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="changePayLater(scope.row,'0')">通过</el-button>
            <el-button size="mini" type="text" @click="changePayLater(scope.row,'1')">不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--  -->
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList"/>
    </el-row>
  </div>
</template>

<script>
import {confirmPayLaterList, queryPayLaterList} from "@/api/distribution";

export default {
  name: "User",
  dicts: ['erp_flow_type', 'erp_pay_type', 'pay_later_status'],
  data() {
    return {
      tabsValue: "",//选项卡下标
      loading: true, // 遮罩层
      ids: [],  // 选中数组
      single: true, // 非单个禁用
      multiple: true, // 非多个禁用
      showSearch: true,// 显示搜索条件
      total: 0,// 总条数
      flowList: [],// 用户表格数据
      title: "",// 弹出层标题
      open: false,// 是否显示弹出层
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: undefined,
        userName: undefined,
        phonenumber: undefined,
      },
      branchForm: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    changePayLater(row, type) {
      let data = {
        id: row.id,
        type: type
      }
      confirmPayLaterList(data).then(res => {
        this.$message.success(res.msg)
        this.getList()
      })
    },
    // 查询流水明细
    getList() {
      this.loading = true;
      queryPayLaterList().then(response => {
          this.flowList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.branchForm = {
        userId: undefined,
        deptId: undefined,
        userName: undefined,
        nickName: undefined,
        password: undefined,
        phonenumber: undefined,
        email: undefined,
        sex: undefined,
        status: "0",
        remark: undefined,
        postIds: [],
        roleIds: []
      };
      this.resetForm("branchForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
  }
};
</script>
<style lang="scss">

</style>
